(function () {
    var SoundManager = Laya.SoundManager;
    var SOUNDSTATUS = Arena.SOUNDSTATUS;

    function Menu() {
        Menu.super(this);
        this.status = "close";
        this.isAnimation = false;

        this.init();
    }
    Laya.class(Menu, "ui.Home.Menu", ui.Home.UI.MenuUI);
    var _proto = Menu.prototype;

    _proto.init = function () {
        this.right = 25;
        this.top = 115;
        // Laya 系统公告, 默认是隐藏的
        if(window.GM && GM.isCall_out === 1 && GM.noticeStatus_out){
            GM.noticeStatus_out(function(data){
                data = data || {};
                // 是否显示系统公告
                if(data.isShowNotice){
                    // 显示系统公告
                    this.btnNotice.disabled = false;
                }

                // 是否需要显示小红点
                if(data.isShowRedPoint){
                    // 显示小红点
                    this.noticeTip.visible = true;
                }
            }.bind(this));
        }

        new ui.Com.BtnSound(this.btnSound, this.soundView, function (status) {
            this.soundStatus.index = status;

            utils.log("点击了声音按钮");
        }.bind(this));

        this.btnFaq.on(Laya.Event.CLICK, this, function(){
            viewer.publish("alert.show", "faq");

            this.showMenu();
            utils.log("点击了新手引导按钮");
        }.bind(this));

        this.btnNotice.on(Laya.Event.CLICK, this, function(){
            // 直接隐藏小红点
            this.noticeTip.visible = false;
            if( GM.noticePopShow_out ){
                GM.noticePopShow_out();
            }

            this.showMenu();
            utils.log("点击了消息按钮");
        }.bind(this));
        
        Laya.stage.on(Laya.Event.CLICK, Laya.stage, function (menu) {
            if(menu.status == "open"){
                if(!menu.bg.hitTestPoint(this.mouseX, this.mouseY)){
                    menu.showMenu();
                }
            }
        }, [this]);
    }

    _proto.showMenu = function () {
        // Laya.timer.callLater(this, function () {
            if(this.isAnimation){return;}

            switch(this.status){
                case "open":
                    Laya.Tween.to(this, {scaleX : 0, scaleY : 0}, 300, null, Laya.Handler.create(this, function () {
                        this.status = "close";
                        this.isAnimation = false;
                        this.visible = false;
                    }));
                    break;
                case "close":
                    this.visible = true;
                    this.scale(0, 0);
                    
                    Laya.Tween.to(this, {scaleX : 1, scaleY : 1}, 300, null, Laya.Handler.create(this, function () {
                        this.status = "open";
                        this.isAnimation = false;
                    }));
                    break;
            }
            this.isAnimation = true;

            viewer.publish("menu.status", this.status);
        // });
    }
})();